package com.cj.ai.service.impl;

import com.cj.ai.domain.AiChatMessage;
import com.cj.ai.domain.MpRequest;
import com.cj.ai.domain.Records;
import com.cj.ai.mapper.RecordsMapper;
import com.cj.ai.service.IRecordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cc
 * @since 2024-08-20
 */
@Service
public class RecordsServiceImpl extends ServiceImpl<RecordsMapper, Records> implements IRecordsService {

    @Override
    public boolean saveMessages(MpRequest mpRequest, List<AiChatMessage> aiChatMessages, String openid) {

        List<Records> recordsList = aiChatMessages.stream().map(item -> {
            Records records = new Records();
            records.setSubject(mpRequest.getSubject());
            records.setContent(item.getContent());
            records.setRole(item.getRole());
            records.setOpenid(openid);
            records.setSessionId(mpRequest.getSessionId());
            // 我提的问题的内容，，， 是选择的
            records.setContent(mpRequest.getContent());
            return records;

        }).collect(Collectors.toList());

       return saveBatch(recordsList);

    }
}
